#include <iostream>
using namespace std;
#define int long long
signed main() {
    int x, y;
    int ret = 0;
    cin >> x >> y;
    if(x < y) {
        swap(x, y);
    }
    ret += (x / y) * y * 4;
    while(x % y != 0){
       if(x % y > y) {
            x = x % y;
            y = y;
       }else {
        int a = x, b = y;
        y = a % b;
        x = b;
       }
       ret += (x / y) * y * 4;
    }
    cout << ret << endl;
    return 0;
}